package com.smart.thrift.config.client;

import com.smart.thrift.discoveryandbalance.discovery.Registry;
import com.smart.thrift.model.common.ThriftClientProperties;
import com.smart.thrift.model.pool.TransportKeyedObjectPool;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class ThriftClientManager {

    private static final Lock lock = new ReentrantLock();

    private static ThriftClientManager manager;

    private ThriftClientManager() {
    }

    private Registry<?> registry;

    private ThriftClientProperties properties;

    private TransportKeyedObjectPool objectPool;

    public static ThriftClientManager getInstance() {
        if (manager == null) {
            try {
                lock.lock();
                if (manager == null) {
                    manager = new ThriftClientManager();
                }
            } finally {
                lock.unlock();
            }
        }
        return manager;
    }


    public Registry<?> getRegistry() {
        return registry;
    }

    public void setRegistry(Registry<?> registry) {
        this.registry = registry;
    }

    public ThriftClientProperties getProperties() {
        return properties;
    }

    public void setProperties(ThriftClientProperties properties) {
        this.properties = properties;
    }

    public TransportKeyedObjectPool getObjectPool() {
        return objectPool;
    }

    public void setObjectPool(TransportKeyedObjectPool objectPool) {
        this.objectPool = objectPool;
    }
}
